package com.wk.jetpackdemo.db;

import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.support.annotation.NonNull;
import android.util.Log;

import com.wk.jetpackdemo.AppContext;
import com.wk.jetpackdemo.db.entities.Book;
import com.wk.jetpackdemo.db.entities.BookUser;
import com.wk.jetpackdemo.db.entities.Loan;
import com.wk.jetpackdemo.db.entities.User;
import com.wk.jetpackdemo.entities.Article;

@Database(entities = {com.wk.jetpackdemo.entities.User.class,Article.class,User.class, Book.class, BookUser.class, Loan.class}, version = 2, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {

    public abstract TestUserDao getTestUserDao();

    public abstract BookDao getBookDao();

    public abstract UserDao getUserDao();

    public abstract ArticleDao getArticleDao();

    public static class Holder {
        public static final AppDatabase INSTANCE = Room.databaseBuilder(AppContext.sContext, AppDatabase.class, "room_db")
                .addCallback(new Callback() {
                    @Override
                    public void onCreate(@NonNull SupportSQLiteDatabase db) {
                        Log.e(TAG, "onCreate:" + db.getPath());
                        super.onCreate(db);
                    }

                    @Override
                    public void onOpen(@NonNull SupportSQLiteDatabase db) {
                        Log.e(TAG, "onOpen:");
                        super.onOpen(db);
                    }
                })
                .build();

    }


    private static final String TAG = "AppDatabase";
}
